<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    
    <ui:composition template="layout.xhtml">
        
        <ui:define name="body">
            
            <h:form id="cesdiForm">
                <h1 class="title">Escrituras de Separacao, Divorcios e Inventarios</h1>
                <p:growl id="messages" showDetail="true" autoUpdate="true" /> 
                <div class="row">
                    <div class="twelve columns"> 

                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Pesquisar</h4></legend>
                            <fieldset>
                                <legend> <h4 style="margin:0 0 10px 0">Cadastro</h4></legend>
                                <p:panel id="charterPanel" style="background: none; border: none;" 
                                         styleClass="container_24 clearfix ">
                                    <p:outputLabel value="Tipo Ato: " styleClass="grid_3"/>
                                    <p:autoComplete styleClass="grid_8" style="width: 28.44%"
                                                    dropdown="true" converter="actcepconverter"   
                                                    var="actCepValue" itemLabel="#{actCepValue.description}" 
                                                    scrollHeight="200" forceSelection="true"
                                                    itemValue="#{actCepValue}" value="#{managerSearchCesdi.charter.actCep}"
                                                    completeMethod="#{managerActCep.autocomplete}" />  

                                    <p:outputLabel value="Reg. Bens " styleClass="grid_5"/>
                                    <div class="grid_8">
                                        <p:selectOneMenu value="#{managerSearchCesdi.charter.propertySystem}" style="width:100%;" >    
                                            <f:selectItem itemLabel=" " />  
                                            <f:selectItems value="#{managerSearchCesdi.enumPropertySystem()}" />  
                                        </p:selectOneMenu>
                                    </div>

                                    <p:outputLabel value="Data Ato: " styleClass="grid_3"/>
                                    <p:calendar showOn="button" styleClass="grid_8" style="width:32.44%"
                                                value="#{managerSearchCesdi.charter.dateAct}"/>

                                    <p:outputLabel value="Data Casamento: " styleClass="grid_4"/>
                                    <p:calendar showOn="button" styleClass="grid_8" style="width:32.44%"
                                                value="#{managerSearchCesdi.charter.dateMarried}"/>

                                    <div class="clear"/>

                                    <p:outputLabel value="Livro: " styleClass="grid_3" />
                                    <p:inputMask mask="?999999999"  placeHolder="" styleClass="grid_8" value="#{managerSearchCesdi.charter.book}"/>

                                    <p:outputLabel value="Livro Compl.: " styleClass="grid_4"/>
                                    <p:inputText styleClass="grid_8" value="#{managerSearchCesdi.charter.bookComp}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="Folha: " styleClass="grid_3" />
                                    <p:inputMask mask="?999999999"  placeHolder=""  styleClass="grid_8" value="#{managerSearchCesdi.charter.leaf}"/> 

                                    <p:outputLabel value="Folha Compl.: " styleClass="grid_4"/>
                                    <p:inputText styleClass="grid_8" value="#{managerSearchCesdi.charter.leafComp}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="Filhos Adultos" styleClass="grid_3" />
                                    <p:inputMask mask="?999999999"  placeHolder=""  styleClass="grid_8" value="#{managerSearchCesdi.charter.numberAdultChildren}"/>


                                    <div class="clear"/>
                                    <p:outputLabel value="Objeto: " styleClass="grid_3"/>
                                    <p:inputTextarea cols="100" rows="4" 
                                                     styleClass="grid_20" value="#{managerSearchCesdi.charter.description}"/> 
                                </p:panel>

                            </fieldset>
                            <fieldset>
                                <legend> <h4 style="margin:0 0 10px 0">Partes</h4></legend>

                                <p:panel id="partsPanel" style="background: none; border: none;" styleClass="container_24 clearfix ">

                                    <p:outputLabel value="Pessoa: "  styleClass="grid_3"/>
                                    <p:selectOneRadio id="typePerson" style="margin-top:-8px;" styleClass="grid_8"
                                                      value="#{managerSearchCesdi.people.tipoDocumento}" >  
                                        <f:selectItems value="#{managerSearchCesdi.typeDocumentList()}" />
                                        <p:ajax event="change" update=":cesdiForm:partsPanel" 
                                                listener="#{managerSearchCesdi.typeDocumentPeople}" />
                                    </p:selectOneRadio>

                                    <div class="clear"/>

                                    <p:outputLabel id="typeDocumentLabel" 
                                                   value="#{managerSearchCesdi.people.tipoDocumento}: " 
                                                   styleClass="grid_3"/>

                                    <p:inputMask id="typeDocumentInput" 
                                                 value="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF' ? 
                                                          managerSearchCesdi.people.cpf : managerSearchCesdi.people.cnpj}"
                                                 rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'OAB' ? false:true}"
                                                 mask="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF' ? 
                                                         '999.999.999-99':'99.999.999/9999-99'}"
                                                 styleClass="grid_8"  > 
                                        <p:ajax event="blur" update=":cesdiForm:partsPanel" 
                                                onstart="bui.show()" oncomplete="bui.hide()"
                                                listener="#{managerSearchCesdi.ajaxVerifyPeopleExist()}" />
                                    </p:inputMask>

                                    <p:blockUI block=":cesdiForm:partsPanel" widgetVar="bui" > 
                                        <p:graphicImage value="media/css/images/ajax-loader.gif"/>
                                    </p:blockUI> 

                                    <p:inputText styleClass="grid_8" 
                                                 rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'OAB'}"
                                                 value="#{managerSearchCesdi.people.OAB}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="Nome:" styleClass="grid_3" />
                                    <p:inputText styleClass="grid_20" 
                                                 value="#{managerSearchCesdi.people.name}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="UF:"  rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'OAB'}" styleClass="grid_3" />

                                    <div class="grid_8">
                                        <p:selectOneMenu  value="#{managerSearchCesdi.people.UFOAB}"  
                                                          rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'OAB'}" style="width:100%;" >  
                                            <f:selectItem itemLabel="Escolha a UF" />
                                            <f:selectItems value="#{managerCountry.countrys()}" />  
                                        </p:selectOneMenu>
                                    </div>

                                    <div class="clear"/>

                                    <p:outputLabel value="RG: " rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF'}" styleClass="grid_3"/>
                                    <p:inputText styleClass="grid_8" rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF'}" value="#{managerSearchCesdi.people.rg}"/> 

                                    <p:outputLabel value="Orgão emissor: " rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF'}" styleClass="grid_4"/>
                                    <p:inputText styleClass="grid_8" rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF'}" value="#{managerSearchCesdi.people.organ}"/> 

                                    <div class="clear"/>

                                    <p:outputLabel value="Data nasc: " rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF'}" styleClass="grid_3"/>
                                    <p:calendar showOn="button" styleClass="grid_8" rendered="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF'}" style="width:32.44%" 
                                                value="#{managerSearchCesdi.people.nasc}"/> 

                                    <p:outputLabel value="Qualidade: " 
                                                   styleClass="#{managerSearchCesdi.people.tipoDocumento.type eq 'CPF' ? 'grid_4':'grid_3'}"/>
                                    <p:autoComplete styleClass="grid_8" style="width: 28.44%" dropdown="true" converter="qualityconverter"   
                                                    var="qualityValue" itemLabel="#{qualityValue.description}" scrollHeight="200"
                                                    itemValue="#{qualityValue}" value="#{managerSearchCesdi.part.partQuality}"
                                                    completeMethod="#{managerSearchCesdi.autocompleteQuality}" />

                                    <div class="clear"/>
                                    

                                </p:panel>
                            </fieldset>
                            <fieldset>
                                <legend> <h4 style="margin:0 0 10px 0">Selos</h4></legend>

                                <p:panel id="stampPanel" 
                                         style="background: none; border: none;" styleClass="container_24 clearfix ">

                                    <p:outputLabel value="Série: "   styleClass="grid_3"/>
                                    <p:inputText  styleClass="grid_8" value="#{managerSearchCesdi.stamp.serie}"/> 

                                    <p:outputLabel value="Número: "  styleClass="grid_4"/>
                                    <p:inputText  styleClass="grid_8" value="#{managerSearchCesdi.stamp.number}"/> 

                                    <p:outputLabel value="Tipo Selo: "  styleClass="grid_3" />
                                    <p:autoComplete styleClass="grid_8" style="width: 28.44%" dropdown="true"
                                                    converter="typestampconverter"   
                                                    value="#{managerSearchCesdi.typeStampObj}"
                                                    var="typeStampValue" itemLabel="#{typeStampValue.name}" 
                                                    itemValue="#{typeStampValue}"
                                                    completeMethod="#{managerTypeStamp.autoComplete}" >

                                        <p:column style="width:20%;text-align:center;background-color: \##{typeStampValue.color};">  
                                        </p:column>  

                                        <p:column style="width:80%">  
                                            #{typeStampValue.name} 
                                        </p:column>
                                    </p:autoComplete>

                                </p:panel>
                            </fieldset>
                            <br/>

                            <div class="buttonAction">
                                <p:commandButton id="searchBtn" value="Pesquisar" 
                                                 actionListener="#{managerSearchCesdi.search()}" 
                                                 icon="ui-icon-search" styleClass="ui-priority-primary"
                                                 update="@form, cesdiTable" />
                                <p:commandButton value="Cancelar"  icon="ui-icon-trash" />
                            </div >


                            <h4 style="margin:0 0 10px 0">Resultado</h4>
                            <p:blockUI block="resultPanel" trigger="searchBtn" > 
                                <p:graphicImage value="media/css/images/ajax-loader.gif"/>
                            </p:blockUI>
                            <p:panel id="resultPanel" 
                                     style="background: none; border: none;" styleClass="container_24 clearfix ">
                                <p:dataTable var="cht" value="#{managerSearchCesdi.charterSDIs}" 
                                             style="white-space: pre;" id="cesdiTable"
                                             emptyMessage="Nenhum registro encontrado"
                                             paginatorPosition="bottom" paginator="true" rows="5"
                                             >
                                    <f:facet name="header">
                                        Escritura
                                    </f:facet> 
                                    <p:column headerText="Ação" style="width: 50px; vertical-align: middle;">  
                                        <p:button icon="ui-icon-search" href="showCesdi.xhtml?cesdiShow=#{cht.id}" style="width: 25px;"/>
                                        <p:button icon="ui-icon-pencil" href="editCesdi.xhtml?cesdiEdit=#{cht.id}" style="width: 25px;"/> 
                                    </p:column> 
                                    <p:column headerText="Tipo" width="100">  
                                        <h:outputText value="#{cht.actCep.description}" />  
                                    </p:column> 
                                    <p:column headerText="Data" width="100" >  
                                        <h:outputText value="#{cht.dateAct}" >
                                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                                        </h:outputText>
                                    </p:column> 
                                    <p:column headerText="Partes" width="100" >  
                                        <p:dataTable var="part"  value="#{cht.parts}">
                                            <p:column headerText="Qualidade">  
                                                <h:outputText value="#{part.partQuality.description}" />
                                            </p:column> 
                                            <p:column headerText="Nome">  
                                                <h:outputText value="#{part.people.name}" />
                                            </p:column> 
                                            <p:column headerText="Doc">  
                                                <h:outputText value="#{part.people.cpf eq null ? part.people.cnpj:part.people.cpf}" />
                                            </p:column> 
                                        </p:dataTable>
                                    </p:column> 
                                    <p:column headerText="Selos" rendered="false" >  
                                        <p:dataTable value="#{cht.stamp}" var="stam">
                                            <p:column headerText="Número">  
                                                <h:outputText value="#{stam.number}" />
                                            </p:column> 
                                            <p:column headerText="Série">  
                                                <h:outputText value="#{stam.serie}" />
                                            </p:column> 
                                        </p:dataTable>
                                    </p:column> 
                                </p:dataTable>
                            </p:panel>
                        </fieldset>
                    </div>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>